<html>
<head>
	<meta charset='utf-8' />
	<title>小区信息助手后台</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#content,.nav_div{width:98%;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#content,.nav_div{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>
<body>
<div id='content' style='position:relative;border:0px solid'>
	<h1 style='text-align:center'>小区管理</h1>
	
	<div style='text-align:center;margin:20px 0;display:flex'>
		<select id="province" style='flex:1'>
			<option value="">吉林省</option>
		</select>
		<select id="city" style='flex:1'>
			<option value="">通化市</option>
		</select>
		<select id="county" style='flex:1'>
			<option value="">柳河县</option>
		</select>
	</div>

	<div style='margin:20px 0;text-align:centers'>
		<label><input type="radio" value='all' name='area_type' checked /> 全部</label>
		<label><input type="radio" value='1' name='area_type' /> 待审</label>
		<label><input type="radio" value='2' name='area_type' /> 正常</label>
		<label><input type="radio" value='3' name='area_type' /> 封禁</label>
	</div>

	<div id='area_list'></div>

	<div id='fpage'></div>


</div>


</body>
</html>
<script src='../public/jquery.js'></script>
<script src='../public/fun.js'></script>
<script src='../public/ViewOpenCity.js'></script>
<script>
if(!sessionStorage.after_con_area_pnow){
	sessionStorage.after_con_area_pnow = 1;
}
$(function(){
	//底部导航与显示页面
	$.ajax({
		url:'after_template_bottom_nav.html',
		success(res){
			$('body').append(res);
		}
	});

	//获取开通城市
	GetAndViewOpenCity(province,city,county,function(){
		$('#province,#city,#county').change(function(){
			sessionStorage.after_con_area_pnow = 1;
		});
	// 	//获取当前城市的小区列表
	 	GetAreaListForCurrentCity();
	},1,1);

	$('input[name=area_type]').change(function(){
		sessionStorage.after_con_area_pnow = 1;
	 	GetAreaListForCurrentCity();
	});
});

//获取当前城市的小区列表
function GetAreaListForCurrentCity(){
	var data = {
		type:'GetAreaListForCurrentCity',
		city_code:GetCurrentCitycode().code,
		db_host:GetCurrentCitycode().db_host,
		db_name:GetCurrentCitycode().db_name,
		stat:GetCurrentAreaStatType(),
		pnow:sessionStorage.after_con_area_pnow
	}
	AjaxAfter(data,function(res){
		if(!/^{.*}$/.test(res)){
			return;
		}
		var tmp = JSON.parse(res);
		sessionStorage.admin_token1 = tmp.token1;
		ParseAreaList(tmp.data);
	});
}

//解析小区列表数据到元素
function ParseAreaList(area_list){
	var tmp_str = '';
	if(!area_list || area_list == 'err1' || area_list.length < 1){
		$('#area_list').html(tmp_str);
		var max_page = parseInt(sessionStorage.after_con_area_pnow)-1;
		Fpage(parseInt(sessionStorage.after_con_area_pnow),max_page,function(p){
			sessionStorage.after_con_area_pnow = p;
			GetAreaListForCurrentCity();
		},1,1,'#fpage');
		return;
	}

	for(var i=0;i<area_list.length;i++){
		//C(area_list[i]);
		switch(area_list[i].stat){
			case '1':var stat_str = '<span style="color:blue">待审</span>';var stat_str2 = '<button>正常</button>';break;
			case '2':var stat_str = '正常';var stat_str2 = '<button>封禁</button>';break;
			case '3':var stat_str = '<span style="color:red">封禁</span>';var stat_str2 = '<button>待审</button>';break;
		}
		tmp_str += "<div style='display:flex;text-align:center;margin:10px'><div style='flex:1;text-align:left'><a onclick='JumpAreaInfoList(" + area_list[i].id + ")' >" + area_list[i].area_name + "</a></div><div style='width:50px;font-size:12px;line-height:24px'>"  + stat_str + "</div><span style='text-decoration:none;color:blue' onclick=ChangeAreaStat(" + area_list[i].id + ")>"+stat_str2+"</span><span onclick='JumpAreaUserList(" + area_list[i].id + ")' style='color:blue;margin-left:10px' >成员管理</span></div>";
	}
	$('#area_list').html(tmp_str);
	var max_page = parseInt(sessionStorage.after_con_area_pnow)+1;
	Fpage(parseInt(sessionStorage.after_con_area_pnow),max_page,function(p){
		sessionStorage.after_con_area_pnow = p;
		GetAreaListForCurrentCity();
	},1,1,'#fpage');
}

//跳转到小区管理页
function JumpAreaInfoList(id){
	sessionStorage.after_current_area_id = id;
	sessionStorage.after_current_area_cityCode = GetCurrentCitycode().code;
	sessionStorage.after_current_area_dbName = GetCurrentCitycode().db_name;
	sessionStorage.after_current_area_dbHost = GetCurrentCitycode().db_host;
	sessionStorage.after_con_msg_pnow = 1;
	location.href='after_con_msg.html';
}


//跳转到小区用户列表
function JumpAreaUserList(id){
	sessionStorage.after_current_area_id = id;
	sessionStorage.after_current_area_cityCode = GetCurrentCitycode().code;
	sessionStorage.after_current_area_dbName = GetCurrentCitycode().db_name;
	sessionStorage.after_current_area_dbHost = GetCurrentCitycode().db_host;
	sessionStorage.after_con_area_user_list_pnow = 1;
	location.href='after_con_area_user_list.html';
}



//更改小区状态
function ChangeAreaStat(id){
	if(!id){
		return;
	}
	var data = {
		type:'ChangeAreaStat',
		city_code:GetCurrentCitycode().code,
		db_name:GetCurrentCitycode().db_name,
		db_host:GetCurrentCitycode().db_host,
		id:id
	}
	C(data);
	AjaxAfter(data,function(res){
		C(res);
		if(!/^{.*}$/.test(res)){
			return;
		}
		var tmp = JSON.parse(res);
		sessionStorage.admin_token1 = tmp.token1;
		switch(tmp.stat){
			case 'err1':A('请求异常！');break;
			case 'err2':A('操作失败！');break;
			case 'ok':location.reload();break;
		}
	});
}


//获取当前选择的小区状态类别
function GetCurrentAreaStatType(){
	return $("input[type=radio]:checked").val();
}


</script>